package com.yunji.web.base;

import com.yunji.aggregate.model.dto.base.BelongParam;
import com.yunji.aggregate.model.vo.base.BelongStatisticsVO;
import com.yunji.aggregate.service.BaseAggregateService;
import com.yunji.base.business.BelongBusiness;
import com.yunji.base.domain.BelongDO;
import com.yunji.base.params.BelongPageParam;
import com.yunji.base.params.WalletParam;
import com.yunji.base.vo.ShortCutVO;
import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.utils.ExcelUtil;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.storage.vo.TreeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Package com.yunji.web.user
 * FileName:	BelongController.java
 * Copyright:	Copyright © 2024 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-08-15 17:58:06.892
 * Description:
 * 所属信息交互
 * Modification History:
 * Author					Date						Version			Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-08-15 17:58:06			1.0				1.0 Version
 */
@RestController
@Api(tags = "管理端-所属信息")
@RequestMapping("/container/belong")
public class BelongController extends BaseController {
    @Resource
    BelongBusiness business;

    @Resource
    BaseAggregateService aggregate;

    @ApiOperation("钱包列表")
    @GetMapping("walletList")
    public Response<List<BelongStatisticsVO>> walletList(WalletParam param) {
        BelongParam belong = new BelongParam();
        BeanUtils.clone(param, belong);
        return ResponseHelper.successWithPage(aggregate.belongList(belong));
    }

    @ApiOperation("导出钱包列表")
    @PostMapping("/walletExport")
    @PreAuthorize("@ss.hasPermi('transaction:wallet:export')")
    public void walletExport(WalletParam param) {
        BelongParam belong = new BelongParam();
        BeanUtils.clone(param, belong);
        List<BelongStatisticsVO> list = aggregate.belongList(belong);
        ExcelUtil<BelongStatisticsVO> util = new ExcelUtil<>(BelongStatisticsVO.class);
        util.hideColumn("updateName", "remarks", "createBy",
                "createName", "updateBy", "createTime");
        util.exportExcel(response, list, "钱包数据");
    }

    @GetMapping("/list")
    @ApiOperation("查询所属信息列表")
    public Response<List<BelongDO>> list(BelongPageParam belong) {
        return ResponseHelper.successWithPage(business.search(belong));
    }

    @PostMapping("/export")
    @ApiOperation("导出所属信息列表")
    @Log(title = "所属信息", businessType = BusinessType.EXPORT)
    public void export(BelongPageParam belong) {
        List<BelongDO> list = business.search(belong);
        ExcelUtil<BelongDO> util = new ExcelUtil<>(BelongDO.class);
        util.exportExcel(response, list, "所属信息数据");
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("获取所属信息详细")
    public Response<BelongDO> select(@PathVariable("id") Long id) {
        return ResponseHelper.success(business.select(id));
    }

    @PostMapping
    @ApiOperation("创建所属信息")
    @Log(title = "所属信息", businessType = BusinessType.INSERT)
    public Response<Long> create(@RequestBody BelongDO belong) {
        return ResponseHelper.success(business.create(belong));
    }

    @PutMapping
    @ApiOperation("修改所属信息")
    @Log(title = "所属信息", businessType = BusinessType.UPDATE)
    public Response<String> update(@RequestBody BelongDO belong) {
        business.update(belong);
        return ResponseHelper.success("编辑成功");
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除所属信息")
    @Log(title = "所属信息", businessType = BusinessType.DELETE)
    public Response<String> remove(@PathVariable Long... ids) {
        business.delete(ids);
        return ResponseHelper.success("删除成功");
    }

    @ApiOperation("所属单位树")
    @GetMapping("/belongTree")
    public Response<List<TreeVO>> belongTree(@RequestParam Integer require) {
        return ResponseHelper.success(business.belongTree(require));
    }

    @ApiOperation("设置快捷菜单")
    @GetMapping("/setHomeMenu/{menuIds}")
    public Response<String> setHomeMenu(@PathVariable Long... menuIds) {
        business.setHomeMenu(menuIds);
        return ResponseHelper.success();
    }

    @ApiOperation("获取快捷菜单")
    @GetMapping("/getHomeMenu")
    public Response<List<ShortCutVO>> getHomeMenu() {
        return ResponseHelper.success(business.getHomeMenu());
    }

    /*-------------------------------------------搜索栏-----------------------------------------------*/

    @ApiOperation("所属名称/账户名称匹配搜索")
    @GetMapping("searchBelongName")
    public Response<List<String>> searchBelongName(@RequestParam("belongName") String belongName) {
        return ResponseHelper.successWithPage(business.searchBelongName(belongName));
    }

    @ApiOperation("账户的电话号(非小程序用户的电话号)匹配搜索")
    @GetMapping("searchPhoneNumber")
    public Response<List<String>> searchPhoneNumber(@RequestParam("phoneNumber") String phoneNumber) {
        return ResponseHelper.successWithPage(business.searchPhoneNumber(phoneNumber));
    }

}
